package com.atguigu.yygh.apartment.controller.api;

import com.atguigu.yygh.apartment.service.ApartmentInfoService;
import com.atguigu.yygh.apartment.service.ApartmentService;
import com.atguigu.yygh.apartment.service.ChamberService;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.hosp.Apartment;
import com.atguigu.yygh.model.hosp.ApartmentInfo;
import com.atguigu.yygh.vo.hosp.ApartmentInfoQueryVo;
import com.atguigu.yygh.vo.hosp.ApartmentQueryVo;
import com.atguigu.yygh.vo.hosp.ChamberVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/apartment/apartmentInfo")
public class ApartmentApiController {
    @Autowired
    private ApartmentInfoService apartmentInfoService;

    @Autowired
    private ChamberService chamberService;

    @ApiOperation(value = "查询宿舍列表")
    @GetMapping("findApartmentList/{page}/{limit}")
    private Result findApartmentList(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     ApartmentInfoQueryVo apartmentQueryVo) {
        System.out.println(apartmentQueryVo.toString());
        Page<ApartmentInfo> apartmentInfos = apartmentInfoService.selectApartmnetInfoPage(page, limit, apartmentQueryVo);
        return Result.ok(apartmentInfos);
    }
//    @ApiOperation(value = "查询宿舍列表")
//    @GetMapping("findApartmentList2/{page}/{limit}")
//    private Result findApartmentList2(@PathVariable Integer page,
//                                     @PathVariable Integer limit,
//                                     String apartmentType) {
//        System.out.println(apartmentType);
//
//        return null;
//    }

    @ApiOperation(value = "根据宿舍名称查询")
    @GetMapping("findByApartmentName/{apartmentName}")
    public Result findByApartmentName(@PathVariable String apartmentName){
        List<ApartmentInfo> list = apartmentInfoService.findByApartmentName(apartmentName);
        return Result.ok(list);
    }
    @ApiOperation(value = "根据宿舍编号获得寝室信息")
    @GetMapping("getChamberList/{apartmentCode}")
    public Result getChamberList(@PathVariable String apartmentCode){
        List<ChamberVo> list = chamberService.findChamberTree(apartmentCode);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据宿舍编号获得规则")
    @GetMapping("findApartmentDetail/{apartmentCode}")
    public Result apartmentDetail(@PathVariable String apartmentCode){
        Map<String,Object> map = apartmentInfoService.findApartmentDeatil(apartmentCode);
        return Result.ok(map);
    }
}
